<?php

use Jialeo\LaravelSchemaExtend\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class InitNewJikaRelation extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('jika_box_relations', function (Blueprint $table) {
            $table->comment = '集卡和盲盒绑定的关系';
            
            $table->integer('jika_id')->index()->unsigned();
            $table->integer('box_id')->index()->unsigned();
            $table->timestamps();

            $table->foreign('box_id')->references('id')->on('boxes')
                ->onUpdate('cascade')->onDelete('cascade');
            $table->foreign('jika_id')->references('id')->on('jika_activity')
                ->onUpdate('cascade')->onDelete('cascade');

            $table->primary(['box_id', 'jika_id']);
        });

        Schema::table('jika_activity', function (Blueprint $table) {
            // $table->string('supplier', 20)->index()->nullable()->comment('供应商名称');
            $table->json('box_ids')->nullable()->comment('绑定的盲盒ids');
            // $table->tinyInteger('status')->comment('1为正常 2为已拉黑')->change();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::disableForeignKeyConstraints();
        // Schema::dropIfExists('admin_role');
        // Schema::dropIfExists('tenant_admin_role');
        // Schema::dropIfExists('role_user');
        Schema::dropIfExists('jika_box_relations');
    }
}
